<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_BoardFunc.php";
	require_once "../../_func/_MngFunc.php";
	require_once "../../_func/_CodeFunc.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>쪽지보내기</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<script language="javascript">
	function SendMsg(){
		var F = document.msgwForm
		var lenchk = 0;
		len = document.getElementsByName("uid[]").length

		for(i=1;i<len;i++){
			if(document.getElementsByName("uid[]")[i].checked){
				lenchk = 1;
				break;
			}
		}
		if(lenchk == 0){
			alert('받는사람을 선택해 주세요');
			return false;
		}

		if(F.message.value.length==0){
			alert('메시지를 입력하세요');
			F.message.focus();
			return false;
		}

		F.submit();
	}
	function SetCheck(){
		var setcheck = false;
		if(document.getElementsByName("uid[]")[0].checked){
			setcheck = true;
		}
		for(i=1;i<document.getElementsByName("uid[]").length;i++){
			document.getElementsByName("uid[]")[i].checked = setcheck
		}
	}
</script>
</head>
<body class="pop">
<?
	if($_POST[mode] == "send"){

		$message = $_POST['message'] ;
		$snd_idx = $_POST[snd_idx];

		if(!$snd_idx){
			$errmsg = "보낸사람정보가 확인 되지 않아 발송을 중지 했습니다.";
			$isback = 1;
		}else{
			if(sizeof($_POST['uid']) < 1){
				$errmsg = "선택회원이 없습니다. 회원을 선택하신 후 다시 시도하세요!";
				$isback = 1;
			}else{
				$db = new MySQLConnection();
				$db->connect();
				//개별 선택인경우
				for($i=0;$i<sizeof($_POST['uid']);$i++){
					$sql = "INSERT INTO BRD_MEMO(rcv_idx,rcv_type,rcv_grp,message,snd_idx,snd_dt)
						 values('".$_POST['uid'][$i]."','person','','$message','$snd_idx',NOW())";
					$rs =& $db->query($sql);
				}
				$errmsg = "메세지가 정상적으로 발송되었습니다.";
				$isback = 0;
			}
		}
		echo "<script language='javascript'>
				alert('$errmsg');
				".(($isback)?"history.go(-1);":"self.close();")."
				</script>";

		exit;
	}

?>
<p class="poptitle"><span>쪽지보내기</span></p>
    <div class="memoplace">
    	<form name="msgwForm" method="post">
    		<input type="hidden" name="mode" value="send">
        <table cellpadding="0" cellspacing="1" border="0" class="bbsTable">
          <colgroup>
          <col width="120px" />
          <col width="*" />
          </colgroup>
          <tr>
            <th>보내는 사람</th>
            <td><?=GetCurrentUser()?><input type="hidden" name="snd_idx" id="snd_idx" value="<?=$session->getString("userno")?>"></td>
          </tr>
          <tr>
          	<th>받는 사람</th>
            <td class="viewbox" >
            	<ul style="height:100px; overflow-y:scroll;">
            		<li><input type="checkbox" id="uid[]" name="uid[]"  onclick="SetCheck();"/> 전체선택</li>
<?
	$list = & GetMemberList();

	if ($list->getLength() == 0)
	{
?>
		<li> 등록된 회원이 없습니다.</li>
<?}else{
		while ($list->hasNext())
		{
			$row 			= & $list->next();
			$member_seq		= $row->getNumber('member_seq');
			$member_id		= $row->getString('member_id');
			$jbnh_name		= $row->getString('jbnh_name');
			$member_useyn	= ( $row->getString('member_delyn') == "N" )  ?  "Y" : "N";
			if($session->getString("userno") != $member_seq){
?>
			<li><input type="checkbox" id="uid[]" name="uid[]" value="<?=$member_seq?>"/> <?=$member_id?></li>
<?
			}

			//관리자등급 1:전체관리자, 2:지역농협관리자, 3:지역관리자
			$member_grade		= RtnMemberGrade($row->getNumber('member_grade'));
		}
}?>


                </ul>
            </td>
          </tr>
          <tr>
          	<td colspan="2">
            <textarea name="message" id="message"></textarea>
          	</td>
          </tr>
        </table>
    </form>
        <div class="BtnList">
            	<ul>
                    <li><input type="button" class="btn_sendmemo" title="보내기" onclick="SendMsg();"/></li>
                    <li><input type="button" class="btn_cancel" onclick="self.close();" title="취소"/></li>
                </ul>
            </div>
	</div>
</body>
</html>
